home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / misc / nilnull / null / null.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  144 lines

  1. /*
  2. **      $VER: misc.c 1.0 (4.4.99)
  3. **
  4. **      main handler routine
  5. **
  6. **      modified 1999 by Andreas R. Kleinert
  7. **      Original Copyright below.
  8. */
  9.  
  10. /****************************************************************************
  11.  *
  12.  *  null driver V0.0 (c)CopyRight 1988, Gunnar Nordmark.  All Rights Reserved.
  13.  *
  14.  *  null-handler Ver. 0.0  20-Jul-1988
  15.  *
  16.  *  Gunnar Nordmark
  17.  *  Nora strand 5
  18.  *  182 34 DANDERYD
  19.  *  SWEDEN
  20.  *
  21.  *  |You may freely distribute this source as long as |
  22.  *  |the Copyright notice is left intact.             |
  23.  ***************************************************************************/
  24.  
  25. #define __USE_SYSBASE
  26.  
  27. #include <exec/types.h>
  28. #include <exec/nodes.h>
  29. #include <exec/lists.h>
  30. #include <exec/ports.h>
  31. #include <exec/libraries.h>
  32. #include <exec/devices.h>
  33. #include <exec/io.h>
  34. #include <exec/memory.h>
  35.  
  36. #include <dos/dos.h>
  37. #include <dos/dosextens.h>
  38. #include <dos/filehandler.h>
  39.  
  40. #include <devices/console.h>
  41.  
  42. #include <proto/exec.h>
  43. #include <proto/dos.h>
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48.  
  49. #include "misc.h"
  50.  
  51.  
  52. UBYTE __aligned version[] = "\0$VER: null 1.0 (4.4.99)";
  53.  
  54.  
  55. /* My Globals */
  56.  
  57. struct ExecBase *SysBase = NULL;
  58. struct Process  *myproc  = NULL;
  59.  
  60. void __saveds start(void)
  61. {
  62.  struct DosPacket  *mypkt;           /* a pointer to the dos packet    */
  63.  struct DeviceNode *mynode;          /* our device node (parmpkt Arg3) */
  64.  struct FileHandle *fh;              /* a pointer to our file handle   */
  65.  long              run = TRUE;       /* handler main loop flag         */
  66.  int               null_open = 0;    /* null open count                */
  67.  
  68.  
  69.  /* Initializing the handler */
  70.  
  71.  SysBase = (*((struct ExecBase **) 4));
  72.  
  73.  myproc      = (struct Process *)FindTask(NULL);
  74.  mypkt       = taskwait(myproc);      /* Wait for my startup message */
  75.  
  76.  
  77.  /* I don't need the name or extra info passed in Arg1/2 */
  78.  
  79.  mynode              = (struct DeviceNode *)BADDR(mypkt->dp_Arg3);
  80.  mynode->dn_Task     = &myproc->pr_MsgPort;
  81.  returnpkt(mypkt, myproc, DOSTRUE, mypkt->dp_Res2);
  82.  
  83.  
  84.  /* done initial stuff, now for some work */
  85.  
  86.  while(run)
  87.   {
  88.    mypkt = taskwait(myproc);
  89.  
  90.    switch(mypkt->dp_Type)         /* find what action to perform */
  91.     {
  92.      case ACTION_FINDINPUT:
  93.      case ACTION_FINDOUTPUT:
  94.       {
  95.        null_open++;
  96.  
  97.        fh          = (struct FileHandle  *) BADDR(mypkt->dp_Arg1);
  98.        fh->fh_Arg1 = mypkt->dp_Type;
  99.        fh->fh_Port = (struct MsgPort *) NULL; /* not interactive */
  100.  
  101.        returnpkt(mypkt, myproc, DOSTRUE, mypkt->dp_Res2);
  102.  
  103.        break;
  104.       }
  105.  
  106.      case ACTION_READ:
  107.       {
  108.        returnpkt(mypkt, myproc, 0, mypkt->dp_Res2); /* zero-length=EOF */
  109.  
  110.        break;
  111.       }
  112.  
  113.      case ACTION_WRITE:
  114.       {
  115.        mypkt->dp_Res1 = mypkt->dp_Arg3;  /* tell em we wrote them all */
  116.  
  117.        returnpktplain(mypkt, myproc);
  118.  
  119.        break;
  120.       }
  121.  
  122.      case ACTION_END:
  123.       {
  124.        null_open--;
  125.  
  126.        if(!null_open) run = FALSE;
  127.  
  128.        returnpkt(mypkt, myproc, DOSTRUE, mypkt->dp_Res2);
  129.  
  130.        break;
  131.       }
  132.  
  133.      default:
  134.       {
  135.        returnpkt(mypkt, myproc, DOSFALSE, ERROR_ACTION_NOT_KNOWN);
  136.  
  137.        break;
  138.       }
  139.    }
  140.  }
  141.  
  142.  mynode->dn_Task = NULL;
  143. }
  144.